﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FilePicker.aspx.cs" Inherits="Admin.FilePicker" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Chọn file</title>
    <style type="text/css">
        html, body
        {
            margin: 0;
            padding: 0;
        }
        .previmage
        {
            margin: 10px;
            max-width: 200px;
            vertical-align: middle;
        }
    </style>
    <telerik:RadCodeBlock ID="codeBlock1" runat="server">
        <script type="text/javascript">
            //<![CDATA[

            function OnClientItemSelected(sender, args) {
                var pvwImage = $get("<%= pvwImage.ClientID %>");
                var imageSrc = args.get_path();

                if (imageSrc.match(/\.(gif|jpg|jpeg|png)$/gi)) {
                    pvwImage.src = imageSrc;
                    pvwImage.style.display = "";
                    pvwImage.alt = imageSrc.substring(imageSrc.lastIndexOf('/') + 1);
                }
                else {
                    pvwImage.style.display = "none";
                }
            }

            //]]>
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
    <script type="text/javascript">
        //A function that will return a reference to the parent radWindow in case the page is loaded in a RadWindow object
        function getRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }

        function OnClientFileOpen(sender, args) {// Called when a file is open.


            var item = args.get_item();

            //If file (and not a folder) is selected - call the OnFileSelected method on the parent page
            if (item.get_type() == Telerik.Web.UI.FileExplorerItemType.File) {
                // Cancel the default dialog;
                args.set_cancel(true);

                // get reference to the RadWindow
                var wnd = getRadWindow();

                //Get a reference to the opener parent page using RadWndow
                var openerPage = wnd.BrowserWindow;

                //if you need the URL for the item, use get_url() instead of get_path()
                openerPage.OnFileSelected(item.get_path()); // Call the method declared on the parent page


                //Close the window which hosts this page
                wnd.close();
            }
        }
    </script>
    <div style="float: left">
    <telerik:RadFileExplorer runat="server" ID="FileExplorer1" Width="550" Height="500"
        OnClientFileOpen="OnClientFileOpen" Skin="Windows7" AllowPaging="true" OnClientItemSelected="OnClientItemSelected">
        <Configuration ViewPaths="~/Uploads" MaxUploadFileSize="10485760" UploadPaths="~/Uploads" DeletePaths="~/Uploads" />
    </telerik:RadFileExplorer>
    </div>
    <div style="float: right;">
            <fieldset style="width: 230px">
                <legend>Preview</legend>
                <img id="pvwImage" src="" runat="server" alt="" class="previmage" style="display: none;" />
            </fieldset>
        </div>
    </form>
</body>
</html>
